package com.vanrui.pcp.autocode.template;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.vanrui.pcp.autocode.model.entry.Config;
import com.vanrui.pcp.autocode.model.entry.Table;
import com.vanrui.pcp.autocode.utils.AutoCodeReader;

public class DataUtil {
	
	private final static Logger logger = Logger.getLogger(DataUtil.class);
	private Config config = new Config();
	

	public List<DataFactory> getFactorys() throws Exception {
		init();
		List<DataFactory> factorys = new ArrayList<DataFactory>();
		for (Table tableName : config.getTables()) {
			DataFactory factory = new DataFactory(config, tableName);
			factorys.add(factory);
		}
		return factorys;
	}
	
	/**
	 * 初始化配置和数据
	 * @throws Exception
	 */
	private void init() throws Exception {
		logger.debug("加载配置文件autoCode.xml");
		AutoCodeReader reader = new AutoCodeReader(config);
		reader.LoadConfig();
		logger.debug("加载配置文件autoCode.xml完毕");
		logger.debug("加载初始化类数据   ...");
		//initData();
	}

}
